<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
<!DOCTYPE>
<html>
<head>
<title>修改登录密码</title>
<script src="${basePath}resources/js/Jquery-md5.js"></script>
</head>
<body>
	<div class="loading"></div>
	<!-- header -->
	<header>
		<a href="javascript:history.go(-1);" class="top_fh">修改登录密码</a>
	</header>
	<!-- header end -->

	<div class="page nb_page">
		<div class="my_ghsjinner my_ghmminner">
			<ul>
                <li>
                    <div>
                        <span>旧密码</span><input id="oldpass" type="password" autofocus class="my_ghmmpsw" placeholder="6-18位字符，区分大小写">
                    </div>
                </li>
                <li><i id="oldpassword_remark">*与原密码不符。</i></li>
                <li>
                    <div>
                        <span>新密码</span><input class="my_ghmmSetPassword" id="newpass" type="password" placeholder="6-18位字符，区分大小写">
                    </div>
                </li>
                <li><i id="newpassword_remark">*6-18位字符，且不能与提现密码一致。</i></li>
                <li>
                    <div>
                        <span>再次输入</span><input type="password" class="my_ghmmPassword" placeholder="请再次确认新密码">
                    </div>
                </li>
                <li><i id="password_remark">*您二次输入的密码不一致。</i></li>
                <%--<li>
                  <div>
                    <div style="width: 75%; float: left;">
                      <span>验证码</span> <input id="vildCode" style="width: 50%;"
                        type="text" placeholder="请输入验证码">
                    </div>
                    <div style="width: 25%; float: right;">
                      <img id="captchaImage" src="${basePath}authCode" alt=""
                        onclick="chageCode();" />
                    </div>
                  </div>
                <li><i id="vildCode_remark"></i></li>--%>
                <li class='get_yzm'>
                    <div>
                        <input id="mobliecode" type="text" class="my_ghmmCatpcha" placeholder="请输入验证码"><a
                            id="getSMSCode" href="JavaScript:;">获取验证码</a>
                    </div> <input type="hidden" id="oldpassword"><input type="hidden"
                                                                        id="newpassword">
                </li>
                <li><i id="smscode_remark">*您输入的验证码有误。</i></li>
            </ul>

			<div class="my_qrbutton">
				<a id="changpassword" href="javascript:void(0);" class='cur'>确认</a>
			</div>
		</div>
	</div>

</body>
</html>
<script>
function chageCode() {
    $('#captchaImage').attr('src', '${basePath}authCode?abc=' + Math.random()); //链接后添加Math.random，确保每次产生新的验证码，避免缓存问题。
}

//更换密码my_ghmm.html********************************************修改
var regPassword=/^\w{6,18}$/;
var oldpassword="", newpassword="", password="",code="";
$(".my_ghmmpsw, .my_ghmmSetPassword, .my_ghmmPassword, #getSMSCode").on("focus", function(){     /*得到焦点*/
    $(".my_ghmmpsw, .my_ghmmSetPassword, .my_ghmmPassword, #getSMSCode").parent().parent().next().children().removeClass("cur");
    $(this).removeClass("cur");
});
//验证码倒计时
var setTime = 0;
function yzsetTime($index){
    var yzmset = window.setInterval(function () {
        setTime++;
        if (setTime == 60) {
            setTime = 0;
            $($index).removeClass('cur').text('获取验证码');
            getSMScode();
            clearInterval(yzmset);
        } else {
            $($index).text('重新发送（' + (60 - setTime) + 's）');
        }
    }, 1000);
};
//获取验证码
var getSMScode = function (){
    $("#getSMSCode").click(function () {
        oldpassword=$(".my_ghmmpsw").val();
        newpassword=$(".my_ghmmSetPassword").val();
        password=$(".my_ghmmPassword").val();
        if (!regPassword.test(oldpassword)) {
            $("#oldpassword_remark").text("*与原密码不符。").addClass("cur");
            //alert('温馨提示:请输入原密码');
        } else if (!regPassword.test(newpassword)) {
            $("#newpassword_remark").text("*6-18位字符，且不能与提现密码一致。").addClass("cur");
            //alert('温馨提示:请输入新密码');
        } else if (!(password!="" && password==newpassword)){
            $("#password_remark").text("*您二次输入的密码不一致。").addClass("cur");
            //alert('温馨提示:您两次输入的密码不一致');
        } else if (regPassword.test(oldpassword) && regPassword.test(newpassword) && password!="" && password==newpassword) {
            if (!$(this).hasClass('cur')) {
                $(this).addClass('cur').text('重新发送（60s）');
                $(this).unbind("click");
                yzsetTime($(this));

                $.ajax({
                    url: '${basePath}sms/sendMobileCode',
                    type: 'POST',
                    /*data: {
                     "vildCode": $("#vildCode").val()
                     },*/
                    error: function(response) {
                        ViewHelper.func.ajaxWechatErrorMessage(response);
                    },
                    success: function(ret) {
                        console.log(ret);
                        if (ret.result) {
                            alert('温馨提示:' + ret.info);
                        } else {
                            $("#vildCode_remark").text(ret.info);
                        }
                    }
                });
            }
        }
    });
}
getSMScode();

//确认按钮
$("#changpassword").click(function() {
    oldpassword = $("#oldpass").val();
    newpassword = $("#newpass").val();
    password=$(".my_ghmmPassword").val();
    code = $("#mobliecode").val();
    if (typeof(oldpassword) == "undefined" || oldpassword.length <= 0) {
        $("#oldpassword_remark").text("原始登录密码不能为空").addClass("cur");

    }else if(!regPassword.test(oldpassword)){
        $("#oldpassword_remark").text("*与原密码不符。").addClass("cur");

    }else if (typeof(newpassword) == "undefined" || newpassword.length <= 0) {
        $("#newpassword_remark").text("新登录密码不能为空").addClass("cur");

    }else if(!regPassword.test(newpassword)) {
        $("#newpassword_remark").text("*6-18位字符，且不能与提现密码一致。").addClass("cur");

    }else if (typeof(password) == "undefined" || password.length <= 0) {
        $("#password_remark").text("确认密码不能为空").addClass("cur");

    }else if(!(password!="" && password==newpassword)){
        $("#password_remark").text("*您二次输入的密码不一致。").addClass("cur");

    }else if (typeof(code) == "undefined" || code.length <= 0) {
        $("#smscode_remark").text("短信验证码不能为空").addClass("cur");

    } else if(regPassword.test(oldpassword) && regPassword.test(newpassword) && password!="" && password==newpassword && code!=""){
        $.ajax({
            url: '${basePath}wechat/indivdual/changeloginpassword',
            type: 'POST',
            data: {
                "oldPassword": createPassword(oldpassword, oldpassword),
                "newPassword": createPassword(newpassword, newpassword),
                "mobliecode": code
            },
            error: function(response) {
                ViewHelper.func.ajaxWechatErrorMessage(response);
            },
            success: function(ret) {
                if (ret.result) {
                    $(".my_ghmmpsw").addClass("cur");
                    alert("修改密码成功");
                } else {
                    console.log(ret);
                    alert(ret.failType);

                    switch (ret.failType) {
                        case 1:
                            $("#smscode_remark").text(ret.info);
                            break;
                        case 2:
                            $("#newpassword_remark").text(ret.info);
                            $("#newpassword_remark").removeClass("cur");
                            break;
                        case 3:
                            $("#oldpassword_remark").text(ret.info);
                            break;
                    }

                }
            }
        });
    }

});











/*$("#getSMSCode").click(function() {
    var vildCode = $("#vildCode").val();
    if (typeof(vildCode) == "undefined" || vildCode.length <= 0) {
        $("#vildCode_remark").text("*验证码不能为空。");
    } else {
        $.ajax({
            url: '${basePath}sms/sendMobileCode',
            type: 'POST',
            /!*data: {
                "vildCode": $("#vildCode").val()
            },*!/
            error: function(response) {
                ViewHelper.func.ajaxWechatErrorMessage(response);
            },
            success: function(ret) {
                console.log(ret);
                if (ret.result) {
                    alert('温馨提示:' + ret.info);
                } else {
                    $("#vildCode_remark").text(ret.info);
                }
            }
        });
   /!* }*!/
});

$("#changpassword").click(function() {
    var oldpassword = $("#oldpass").val();
    var newpassword = $("#newpass").val();
    var code = $("#mobliecode").val();
    if (typeof(oldpassword) == "undefined" || oldpassword.length <= 0) {
        $("#oldpassword_remark").text("原始登录密码不能为空");
    } else if (typeof(newpassword) == "undefined" || newpassword.length <= 0) {
        $("#newpassword_remark").text("新登录密码不能为空");
    } else if (typeof(code) == "undefined" || code.length <= 0) {
        $("#smscode_remark").text("短信验证码不能为空");
    } else {
        $.ajax({
            url: '${basePath}wechat/indivdual/changeloginpassword',
            type: 'POST',
            data: {
                "oldPassword": createPassword(oldpassword, oldpassword),
                "newPassword": createPassword(newpassword, newpassword),
                "mobliecode": code
            },
            error: function(response) {
                ViewHelper.func.ajaxWechatErrorMessage(response);
            },
            success: function(ret) {
                if (ret.result) {
                    alert("修改密码成功");
                } else {
                    console.log(ret);
                    alert(ret.failType);

                    switch (ret.failType) {
                    case 1:
                        $("#smscode_remark").text(ret.info);
                        break;
                    case 2:
                        $("#newpassword_remark").text(ret.info);
                        $("#newpassword_remark").removeClass("cur");
                        break;
                    case 3:
                        $("#oldpassword_remark").text(ret.info);
                        break;
                    }

                }
            }
        });
    }

});*/
</script>